<?php

	/**
	 * File : mini_toolbar_button.php
	 * Description : Définition et fonctions d'un bouton du composant ktkMiniToolbar
	 * Date : 07.08.2012 15:17:47
	 * 
	 * This file is part of Phenix.  Phenix is free software: you can
	 * redistribute it and/or modify it under the terms of the GNU General Public
	 * License as published by the Free Software Foundation, version 2.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT
	 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
	 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
	 * details.
	 *
	 * You should have received a copy of the GNU General Public License along with
	 * this program; if not, write to the Free Software Foundation, Inc., 51
	 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
	 *
	 * Nils Schaetti <n.schaetti@gmail.com>
	**/

	/**
	 * Cette classe représente un bouton d'une mini toolbar
	 */
	class ktkMiniToolbarButton implements KTKWidgets
	{
		
		
		/*************
		 * Propriétés
		**************/
		
		/**
		 * Lien vers l'image de l'icone
		 */
		 private $Image = '';
		 
		 /**
		  * Lien vers lequel le bouton pointe
		  */
		 private $Link = '';
		 
		 /**
		  * Le bouton n'a pas de bord à gauche
		  */
		 private $noBorderLeft = false;
		 
		 /**
		  * Le bouton n'a pas de bord à droite
		  */
		 private $noBorderRight = false;
		 
		 /**
		  * Position du bouton
		  */
		 private $Position = 'right';
		 
		/**
		 * Bouton visible invisible
		 */
		private $Visible = true;
		 
		/**
		 * Nom du bouton
		 */
		private $Name;
		
		/*************
		 * Fonctions
		 *************/
		 
		/*
		 * Constructeur
		 */
		 public function ktkMiniToolbarButton($Name, $Image, $Link, $Position = 'right', $noBorderLeft = false, $noBorderRight = false)
		 {
			 $this->Name = $Name;
			 $this->Image = $Image;
			 $this->Link = $Link;
			 $this->noBorderLeft = $noBorderLeft;
			 $this->noBorderRight = $noBorderRight;
			 $this->Position = $Position;
		 }
		 
		 /*
		  * Renvoi le code de la barre
		  */
		  public function getCode()
		  {
			  $style = '';
			  $radius_left = 0;
			  $radius_right = 0;
			  
			  // Code du bouton
			  $code = <<< _DELIMITER_
			  <div class="ktkMiniToolbarButton" id="{$this->Name}" style="@@_STYLE_@@" onclick="@@_LINK_@@">
			  </div>
_DELIMITER_;

			  // Emplacement
			  $style .= "float: ".$this->Position."; ";
			  
			  // Si il y a un bord à gauche
			  if(!$this->noBorderLeft)
			  {
				  $style .= 'margin-left: 5px; ';
				  $radius_left = 3;
			  }
			  else
				  $style .= 'border-left: solid 0px; ';
			  
			  // Si il y a un bord à droite
			  if(!$this->noBorderRight)
			  {
					$style .= 'margin-right: 5px; ';
					$radius_right = 3;
			  }
			  else
				  $style .= 'border-right: solid 0px; ';
				  
			// Bouton visible
			if($this->Visible)
				$style .= 'visibility: visible; ';
			else
				$style .= 'visibility: hidden; ';
			  
			  // Radius
			  $style .= "border-radius: {$radius_left}px {$radius_right}px {$radius_right}px {$radius_left}px; ";
			  
			  // Image
			  $style .= "background-image: url('".$this->Image."'); ";
			  
			  // Remplacement
			  $code = str_replace('@@_STYLE_@@', $style, $code);
			  $code = str_replace('@@_LINK_@@', $this->Link, $code);
			  
			  // Retourne le code
			  return $code;
		  }
		  
		  /**
		   * Affiche le widget
		   */
		  public function Show()
		  {
			  echo $this->getCode();
		  }
		  
		/**
		 * Rend le bouton invisible
		 */
		public function setHidden()
		{
			$this->Visible = false;
		}
		
		/**
		 * Rend le bouton visisble
		 */
		public function setVisible()
		{
			$this->Visible = true;
		}
		
	}

?>
